package utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author yuyufeng
 * @date 2017/12/21
 */
public class MyDateUtils {
    private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private static DateFormat dateFormatWithTime = new SimpleDateFormat("yyyyMMddHHmm");
    private static DateFormat stringToDateWithTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");


    public static String getDateString(int incr) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, incr);
        Date date = calendar.getTime();
        String result = dateFormat.format(date);
        return result;
    }

    public static String getTodayString() {
        Calendar calendar = Calendar.getInstance();
        Date date = calendar.getTime();
        String result = dateFormat.format(date);
        return result;
    }

    public static String getTodayTimeNow() {
        Calendar calendar = Calendar.getInstance();
        Date date = calendar.getTime();
        String result = dateFormatWithTime.format(date);
        return result;
    }

    public static Date stringToDate(String str) throws ParseException {
        return stringToDateWithTime.parse(str);
    }

    public static int getHour(){
        Calendar calendar = Calendar.getInstance();
       return calendar.get(Calendar.HOUR_OF_DAY);
    }

    public static void main(String[] args) throws ParseException {
        System.out.println(getHour());
    }
}
